package com.ham.mud.commands;

import com.ham.mud.Colors;
import com.ham.mud.ServerConnection;
import com.ham.mud.characters.mobs.Mob;
import com.ham.mud.characters.npcs.VendorNPC;
import com.ham.mud.items.Item;
import com.ham.mud.rooms.Room;
import com.ham.mud.rooms.RoomService;

import java.util.List;

/**
 * Created by hlucas on Jul 19, 2011 at 10:26:43 AM
 */
public class ListCommand extends PlayerCommand {
    @Override
    public void execute(ServerConnection connection, String[] params) {
        Room room = RoomService.getRoom(connection);
        List<Mob> mobs = room.getMobs();
        VendorNPC npc = null;
        for(Mob mob : mobs) {
            if(mob instanceof VendorNPC) {
                npc = (VendorNPC) mob;
                break;
            }
        }

        if(npc == null) {
            connection.printSolo("This is not a shop.");
            return;
        }

        List<Item> npcInventory = npc.getInventory();
        connection.printStart("Items for sale:");
        for(Item item : npcInventory) {
            connection.println("    " + item.getName() + Colors.getSpaces(40, item.getName()) + " - " + item.getPrice() + "g");
        }
        connection.println();
        connection.println("You have " + connection.getPlayer().getGold() + " gold coins.");
        connection.printEnd();
    }

    @Override
    protected String getCommandName() {
        return "list";
    }
}
